var app = getApp(), util = require("../../../resource/js/util.js"), $ = require("../../../resource/utils/underscore"), WxParse = require("../../../resource/wxParse/wxParse.js"), _function = require("../../../resource/function/function.js");

Page({
    data: {
        userInfo: [],
        timestamp: "",
        tk: !1,
        au: !1,
        datum: [],
        money: 0,
        id: 0,
        day: 0,
        au_hint: "",
        is_pay: !1
    },
    onShow: function() {
        _function.system(this);
        var t = wx.getStorageSync("userInfo"), e = (e = (e = "'" + (e = Date.parse(new Date())) + "'").substr(0, 11)).substr(1, 10), n = wx.getStorageSync("is_pay");
        t ? (_function.getUserinfo(this, 1), this.setData({
            timestamp: e,
            is_pay: 1 == n
        }), this.getDatum()) : (_function.getUserinfo(this), this.setData({
            timestamp: e
        }));
        n = wx.getStorageSync("is_pay");
        this.setData({
            is_pay: 1 == n
        });
    },
    getDatum: function() {
        var e = this, t = wx.getStorageSync("userInfo");
        _function.request("entry/wxapp/UserIndex", {
            types: 1,
            uid: t.id
        }, "", function(t) {
            e.setData({
                datum: t.data
            });
        }, this);
    },
    select: function(t) {
        this.setData({
            money: t.currentTarget.dataset.mo,
            id: t.currentTarget.dataset.id,
            day: t.currentTarget.dataset.day
        });
    },
    tk: function(t) {
        this.setData({
            tk: !this.data.tk,
            money: 0
        });
    },
    au: function(t) {
        var e = this, n = t.detail.formId;
        this.setData({
            au: !this.data.au
        }), this.data.au && _function.request("entry/wxapp/UserIndex", {
            types: 6,
            openid: this.data.userInfo.openid,
            uid: this.data.userInfo.id,
            formId: n
        }, "", function(t) {
            0 == t ? e.setData({
                au_hint: "您已经是作者，无需重复申请，请尝试刷新页面变更身份！"
            }) : 1 == t ? e.setData({
                au_hint: "申请成功！请等待管理员审核通过。"
            }) : 2 == t ? e.setData({
                au_hint: "申请失败！请联系管理员。"
            }) : e.setData({
                au_hint: "您已经提交过申请，请耐心等待管理员审核通过！"
            });
        }, this);
    },
    pay: function(t) {
        var e = this, n = wx.getStorageSync("fxid");
        0 < this.data.money ? _function.request("entry/wxapp/Pay", {
            id: this.data.id,
            uid: this.data.userInfo.id,
            openid: this.data.userInfo.openid,
            money: this.data.money,
            types: 3,
            day: this.data.day,
            fxid: n
        }, "", function(t) {
            console.log(t), 1 == t ? _function.hint(3, "支付金额错误!", "温馨提示", function(t) {}) : 1 == t.state ? wx.requestPayment({
                timeStamp: t.timeStamp,
                nonceStr: t.nonceStr,
                package: t.package,
                signType: "MD5",
                paySign: t.paySign,
                success: function(t) {
                    _function.request("entry/wxapp/GetUserInfoOne", {
                        id: e.data.userInfo.id
                    }, "", function(t) {
                        e.setData({
                            tk: !e.data.tk,
                            userInfo: t
                        }), wx.setStorageSync("userInfo", t);
                    }, this);
                },
                fail: function(t) {
                    _function.hint(3, "支付失败^_^!", "网络提示", function(t) {}), console.log(t);
                }
            }) : (console.log(t), _function.hint(1, "网络错误！", "", function(t) {}));
        }, this) : _function.hint(3, "抱歉，您还没有选择购买类型哦！", "", function(t) {});
    },
    linkto: function(t) {
        var e = t.currentTarget.dataset.url, n = t.currentTarget.dataset.types;
        wx.navigateTo({
            url: e + "?types=" + n
        });
    },
    onPullDownRefresh: function() {
        var e = this;
        _function.system(this), _function.request("entry/wxapp/GetUserInfoOne", {
            openid: this.data.userInfo.openid
        }, "", function(t) {
            e.setData({
                userInfo: t
            }), wx.setStorageSync("userInfo", t);
        }, this), this.getDatum(), wx.stopPullDownRefresh();
    }
});